// LadderMainDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NateOnLadder.h"
#include "LadderMainDlg.h"
#include "NateOnApi.h"



CDispNateMessengerApi*   g_pNateOn = NULL;


// CLadderMainDlg dialog

IMPLEMENT_DYNAMIC(CLadderMainDlg, CDialog)

CLadderMainDlg::CLadderMainDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLadderMainDlg::IDD, pParent)
{
}

CLadderMainDlg::~CLadderMainDlg()
{
}

void CLadderMainDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CLadderMainDlg, CDialog)
    ON_WM_DESTROY()
    ON_WM_SHOWWINDOW()
    ON_WM_PAINT()
    ON_WM_TIMER()
    ON_WM_CREATE()
END_MESSAGE_MAP()


// CLadderMainDlg message handlers

void CLadderMainDlg::OnDestroy()
{

    CDialog::OnDestroy();
}

BOOL CLadderMainDlg::InitializeNateOn()
{
    if(g_pNateOn != NULL)
    {
        return TRUE;
    }

    try
    {
        g_pNateOn = new CDispNateMessengerApi;

        if(NULL == g_pNateOn)
        {
            return FALSE;
        }

        if(!g_pNateOn->CreateNateOnDispatch())
        {
            return FALSE;
        }

        g_pNateOn->RegisterGUID (NATEON_LADDER_GUID);
        g_pNateOn->SetMainWindow(GetSafeHwnd());
        g_pNateOn->MonitorBuddyEvent(_T("#AllIds#"));
    }
    catch(...)
    {
        return FALSE;
    }

    return TRUE;
}

void CLadderMainDlg::UninitNateOn()
{
    if(g_pNateOn != NULL)
    {
        g_pNateOn->ReleaseNateOnDispatch();
        delete g_pNateOn;
        g_pNateOn = NULL;
    }
}


void CLadderMainDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
    CDialog::OnShowWindow(bShow, nStatus);

    if(bShow)
    {
    }
}

void CLadderMainDlg::OnPaint()
{
    CPaintDC dc(this); // device context for painting
}

void CLadderMainDlg::OnTimer(UINT_PTR nIDEvent)
{
    CDialog::OnTimer(nIDEvent);
}

int CLadderMainDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;

    return 0;
}

BOOL CLadderMainDlg::Create(CWnd* pParentWnd)
{
    // TODO: Add your specialized code here and/or call the base class

    return CDialog::Create(CLadderMainDlg::IDD, pParentWnd);
}

void CLadderMainDlg::PostNcDestroy()
{
    delete this;
    g_pMainDlg = NULL;

    CDialog::PostNcDestroy();
}
